<?php

/**
 *   OPENSHOP 管理中心taobao 用户管理API
 * 
 *   @link        http://baison.com.cn
 *   @copyright   Baison, Inc.
 *   @package     OpenShop
 *   @version     $Id: api_tb_user.php,v 1.0 2009/10/10 08:36:58 created$
 *   @author      FillBag <fillbag@hotmail.com>
 */

define('IN_OS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . '/includes/modules/taobao.api/cls_api.php');
$exc = new exchange($os->table('taobao_goods'), $db, 'goods_id', 'goods_sn');

if ($_REQUEST['act'] == 'list'){	
	//检查权限
	admin_priv();
	
	$obj_api = new taobao_api();
	$obj_api->api_method = 'taobao.items.all.get';
	$obj_api->api_fields = 'approve_status,iid,num_iid,title,nick,type,cid,pic_path,num,props,
	                        valid_thru,list_time,price,has_discount,has_invoice,has_warranty,
	                        has_showcase,modified,delist_time,postage_id,seller_cids,outer_id';
	$smarty->assign('goods_items', $obj_api->fetchItems('item'));
	
    assign_query_info();
    
    $smarty->display('api_tb_goods_list.tpl');
}elseif($_REQUEST['act'] == 'get_item'){
	$obj_api = new taobao_api();
	$obj_api->api_method = 'taobao.item.get';
	$obj_api->api_fields = 'approve_status,iid,num_iid,title,nick,type,cid,pic_path,num,props,
	                        valid_thru,list_time,price,has_discount,has_invoice,has_warranty,
	                        has_showcase,modified,delist_time,postage_id,seller_cids,outer_id';
	$result = $obj_api->fetchItem(array('num_iid'=>$_GET['gid']));
	$val = $result['item'];
	$tb_goods = array(
//        'goods_id'                 => intval($val['num_iid']),
        'cat_id'                   => intval($val['cid']),
        'goods_sn'                 => $val['iid'],    
        'goods_name'               => $val['title'],
        'brand_id'                 => 0,
        'goods_number'             => $val['num'],
        'market_price'             => $val['price'],
        'shop_price'               => $val['price'],       
        'goods_brief'              => empty($val['desc']) ? '' : trim($val['desc']),
        'goods_desc'               => empty($val['desc']) ? '' : trim($val['desc']),
        'goods_thumb'              => $val['pic_path'],
        'goods_img'                => $val['pic_path'],
        'original_img'             => $val['pic_path'],
        'is_on_sale'               => ($val['approve_status']=='onsale' ? 1 : 0),
        'add_time'                 => strtotime($val['list_time']),
        'sort_order'               => 0,
        'last_update'              => strtotime($val['modified'])     
    );
    if(!$exc->is_only('goods_sn', $val['iid'])){    
    	$db->autoExecute($os->table('taobao_goods'), $tb_goods, 'UPDATE', "goods_sn = '$val[iid]'");
    }else{
    	$db->autoExecute($os->table('taobao_goods'), $tb_goods, 'INSERT');
    }
}
?>